<template>
    <div class="statistics-content">
        <van-grid :gutter="10" :column-num="3" :icon-size="50">
            <van-grid-item v-for="(value,index) in groupList" :key="index" :icon="value.icon" :text="value.text" :to="value.to" />
        </van-grid>
    </div>
</template>

<script>
import {Toast,Grid, GridItem} from 'vant';
export default {
    components:{[Grid.name]: Grid,[GridItem.name]: GridItem},
    data: function() {
        return {
            groupList:[
                {icon:'bar-chart-o',text:'业务量统计',to:'/mobile/admin/statisticsyw'},
                {icon:'chart-trending-o',text:'容量统计',to:'/mobile/admin/statisticsrl'},
                {icon:'notes-o',text:'报告统计',to:'/mobile/admin/statisticsbg'},
                {icon:'cash-back-record',text:'对账统计',to:'/mobile/admin/statisticsdz'}, 
                {icon:'description',text:'报告汇总明细',to:'/mobile/admin/statisticsmx'}
            ],
            param: {
                account: '',
                password: '',
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    mounted(){
        let role=this.getQueryVariable('role');
        console.log('role',role)
        if(role){
            if(role === 'jqsadmin'){
                this.param.account='jqjtlinkadmin';
                this.param.password='123456';
                this.submitForm();
                return;
            }

            if(role === 'jqoadmin'){
                this.param.account='jqjtlinkuser';
                this.param.password='123456';
                this.submitForm();
                return;
            }
        }
    },
    methods: {
        submitForm() {
            const loading = this.$loading({text: '登录中'});
            this.$http.post(this.$API.LOGIN,this.param)
            .then((res)=>{
                loading.close();
                console.log('登录信息',res)
                if(res.code == 1){
                   window.sessionStorage.setItem('jqzxUserId', res.data.id)
                    window.sessionStorage.setItem('userName',res.data.account);
                    window.localStorage.setItem('userInfo',JSON.stringify(res.data));
                    if(this.isMobile){
                        Toast.success('登录成功');
                    }else{
                        this.$message.success('登录成功');
                    }
                    this.$router.push('/');
                }else{
                    if(this.isMobile){
                        Toast.fail(res.msg);
                    }else{
                        this.$message.error(res.msg);
                    }
                }
            })
            .catch((err)=>{
                    this.$message.error('');
                    console.log('error submit!!');
                    return false;
            })
        },
        getQueryVariable(variable) {
            var query = window.location.hash,vars=[];
            if(query && query.indexOf('?')!==-1){
                 vars = query.split("?");
            }
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
            }
            return '';
        }
    },
};
</script>

<style scoped>
.statistics-content{
    padding:30px 0;
}
</style>
<style>
    .statistics-content .van-icon{
        color:#9acafc;
    }
</style>